<template>
<Modal
	v-model="show"
	title="选择对象"
	:width="1000"
	>
	<div>
		<Table :columns="Columns" :data="list" style="width: 100%;" border ref="table">
			<div slot="footer" style="border-top: 1px solid #eee;padding: 0 10px; text-align: right;    font-size: 14px;">
				
				<div style="float:right;">
					<Page :total="count" show-elevator show-total @on-change="goto_page" />
				</div>
			</div>
		</Table>
	</div>
	<div slot="footer" style="text-align: center;">
		<Button type="success" size="large" @click="save">提交</Button>
	</div>
</Modal>


</template>

<script>


export default {
    name: 'target_info',
    data () {
		let self = this;
        return {
			show:false,
			Columns: [
				{
					type: 'selection',
					width: 60,
					align: 'center'
				},
				{
					title: '权限组名称',
					key: 'name',
					align: 'center',
                    width: 100
                },
				{
                    title: '职能描述',
					key: 'info',
					
                },
				{
                    title: '成员数量',
					key: 'num',
					width: 150,
                },
				{
                    title: '添加时间',
					key: 'addtime',
					width: 150,
                },
			],
			list:[],
			page:1,
			count:0,
        };
	},
	props:['value','id','cinfo'],
	created(){
		
		this.load_data();
	},
    watch:{
		value(val){
			var self = this;
			this.show = val;
			if(val){
				var objData = self.$refs['table'].$refs.tbody.objData;
				var ids = this.cinfo.groups.split(',');
				
				for(var i in objData){
					if(ids.in_array(objData[i].id)){
						objData[i]._isChecked=true;
					}
					else{
						objData[i]._isChecked=false;
					}
				}
				
			}
		},
		show(val){
			this.$emit('input',val);
		}
    },
	methods:{
		
		load_data(){
			var self = this;
			var postdata = {
				page:this.page,
				f:{
					is_enable:1
				}
			};
			Whttp.load('System/Privgroup/get_list',postdata,function(result){
				self.list = result.list;
				self.count = parseInt(result.count);
			});
		},
		
		qurey(){
			this.load_data();
		},
		goto_page(page){
			this.page = page;
			this.load_data();
		},
		handleSubmit(name){
			var self = this;
			
			this.$refs[name].validate((valid) => {
				if (valid) {
					self.save();
				}
			})
		},
		save(){
			var sels = this.$refs['table'].getSelection();
			var ids = [];
			for(var i=0;i<sels.length;i++){
				ids.push(sels[i].id);
			}
			
			var self = this;
			var postdata = {
				ids:ids.join(','),
				id:this.id
			};
			Whttp.load('System/Msg_template/update_target',postdata,function(result){
				self.$emit('success',result);
				self.show = false;
			});
		},
		
	}
};
</script>

<style scoped>

</style>